home *** CD-ROM | disk | FTP | other *** search
- /*
- This include file should be used when accessing auxillary devices.
- Routines defined:
- int auxopen(name) char name[]
- auxerr(string)
- auxopen returns a file descriptor for use with read and write.
- The global array "auxparams" is used to store device specific information.
- auxerr should be called, whenever the device returns an error message.
- */
-
- char *auxerrprg = NULL,
- *auxerrmsg = NULL,
- *auxdatafile = NULL,
- *auxparams[20];
-
- auxopen(name)
- char name[];
- {
- int i,n,m,fd;
- int id;
- char c,*s, *z;
- char *tty;
- FILE *fp;
- char *home;
-
- s = (char *) malloc(80);
- z = (char *) malloc(80);
- tty = (char *) malloc(80);
- auxerrprg = (char *) malloc(80);
- auxerrmsg = (char *) malloc(80);
- auxdatafile = (char *) malloc(80);
- for(n=0;n<20;n++) {
- auxparams[n] = (char *) malloc(80);
- strcpy(auxparams[n],"");
- }
- #ifdef UNIX
- /* get name of tty */
- system("whoami >/usr/tmp/whoami");
- fp = fopen("/usr/tmp/whoami","r");
- fgets(tty,80,fp); for(i=0;i<strlen(tty);i++) if(tty[i]==10) tty[i]=0;
- fclose(fp); unlink("/usr/tmp/whoami");
- #endif
- fp=fopen("Aux_Config","r");
- #ifdef UNIX
- if(fp==NULL) {
- home = (char *) getenv("HOME");
- s[0]=0;
- if(home != NULL) {strcpy(s,home); strcat(s,"/"); }
- strcat(s,"Aux_Config");
- fp=fopen(s,"r");
- }
- if(fp==NULL) {
- home = (char *) getenv("LISEPRG");
- s[0]=0;
- if(home != NULL) {strcpy(s,home); strcat(s,"/"); }
- strcat(s,"Aux_Config");
- fp=fopen(s,"r");
- }
- #endif
- #ifdef AMIGA
- if(fp==NULL) fp=fopen("LISE:Aux_Config","r");
- #endif
- if(fp==NULL) {
- fprintf(stderr,"auxopen: can not find Aux_Config file\n");
- exit(-1);
- }
- while(!feof(fp)) {
- c=fgetc(fp);
- if(c==';') while(c!=10) c=fgetc(fp); /* skip comment */
- if(c==':') { /* new entry */
- fscanf(fp,"%s\n",s);
- if(strcmp(s,name)==0) { /* entry found */
- n=0; m=0;
- while(c!='#') {
- c=fgetc(fp);
- if(c=='#') break;
- if(c==10) {
- auxparams[n++][m]=0;
- m=0;
- continue;
- }
- if(c==';') { /* skip comment */
- while(c!=10) c=fgetc(fp);
- auxparams[n++][m]=0;
- m=0;
- continue;
- } else { /* store string */
- auxparams[n][m++]=c;
- }
- }
- } else { /* not the right entry */
- while(c!='#') {
- while(c!=10) c=fgetc(fp);
- c=fgetc(fp);
- }
- }
- }
- }
- fclose(fp);
- if(auxparams[0][0]==0) {
- fprintf(stderr,"sorry, device entry >%s< not found in Aux_Config\n",name);
- exit(-1);
- }
- for(n=0;n<20;n++) {
- for(m=strlen(auxparams[n])-1;(auxparams[n][m]==32);m--) auxparams[n][m]=0;
- m = 0; while(auxparams[n][m]==32) m++;
- i = 0; while(auxparams[n][m]!=0) auxparams[n][i++] = auxparams[n][m++];
- auxparams[n][i++] = 0;
- #ifdef UNIX
- i = instr("@",auxparams[n]);
- if(i >= 0) {
- s[0] = 0;
- midstr(s,auxparams[n],0,i - 1);
- strcat(s,tty);
- midstr(z,auxparams[n],i + 1,strlen(auxparams[n]));
- strcat(s,z); strcpy(auxparams[n],s);
- }
- #endif
- }
- fd=open(auxparams[0],2,0);
- strcpy(auxerrprg,auxparams[1]);
- strcpy(auxerrmsg,auxparams[2]);
- strcpy(auxdatafile,auxparams[3]);
- free(s); free(z); free(tty);
- return(fd);
- }
-
- void auxerr(string)
- char string[];
- {
- system(auxerrprg);
- fprintf(stderr,"%s : %s\n",auxerrmsg,string);
- }
-
-